class_name SysUtil
extends RefCounted



static  func add_value_pop_up(text,post = Vector2(0,0),modulate = Color("ffffff")):
	var VALUE_POP_UP = load("res://common/gui/value_pop_up.tscn").instantiate()
	VALUE_POP_UP.text = text
	VALUE_POP_UP.global_position = post
	VALUE_POP_UP.modulate = modulate
	Global.get_tree().get_root().add_child(VALUE_POP_UP)

static func seek_target(arr_node,card_data,global_position):
	return seek_target_arr(arr_node,card_data,global_position).front()
	
static  func seek_target_arr(arr_node,card_data,global_position):
	var arr = []
	for node in arr_node:
		if node != null and card_data.enemy_team == node.card_data.team:
			arr.append(node)
	arr.sort_custom(
		func(a,b):return (global_position-a.global_position).length() < (global_position-b.global_position).length()
	)
	return arr
	
	
static func isAndroid() -> bool :
	return OS.get_name() == "Android"

static func isIOS() -> bool :
	return OS.get_name() == "iOS"

static func isMobile() -> bool :
	return isAndroid() or isIOS()
	
static func deviceOp() -> String :
	var value = ""
	if isAndroid() and  Engine.has_singleton("AndroidNative"):
		var singleton = Engine.get_singleton("AndroidNative")
		value = singleton.getDeviceOp()
	if isIOS() and Engine.has_singleton("IphoneNative"):
		var singleton = Engine.get_singleton("IphoneNative")
		value = singleton.getDeviceOp()
	return value
	
static func deviceType() -> String :
	var value = ""
	if isAndroid() and  Engine.has_singleton("AndroidNative"):
		var singleton = Engine.get_singleton("AndroidNative")
		value = singleton.getDeviceType()
	if isIOS() and Engine.has_singleton("IphoneNative"):
		var singleton = Engine.get_singleton("IphoneNative")
		value = singleton.getDeviceType()
	return value
	
static func appVersion() -> String :
	var value = ""
	if isAndroid() and  Engine.has_singleton("AndroidNative"):
		var singleton = Engine.get_singleton("AndroidNative")
		value = singleton.getAppVersion()
	if isIOS() and Engine.has_singleton("IphoneNative"):
		var singleton = Engine.get_singleton("IphoneNative")
		value = singleton.getAppVersion()
	return value

static func apiVersion() -> String :
	return "1.0.2"
	
static func fillHeight(node : ColorRect) :
	if isAndroid() and  Engine.has_singleton("StatusBar"):
		var singleton = Engine.get_singleton("StatusBar")
		node.custom_minimum_size.x  = singleton.getHeight()
	if isIOS() and  Engine.has_singleton("StatusBar"):
		var _singleton = Engine.get_singleton("StatusBar")


static func createTimer(node :Node ,wait_time : float = 0.1) :
	var timer = Timer.new()
	timer.one_shot = true
	timer.autostart = true
	timer.wait_time =wait_time
	node.add_child(timer)
	return timer

static func get_virtual_height():
	if isMobile():
		if isIOS() :
			return int(float(DisplayServer.virtual_keyboard_get_height() - Global.normal_virtual_keyboard_height)/float(DisplayServer.screen_get_size().y)*1080)
		else :
			return DisplayServer.virtual_keyboard_get_height() - Global.normal_virtual_keyboard_height
	else :
		return 0

